package com.threeti.mecool.core.infrastructure.persistence.acl;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.threeti.mecool.core.domain.model.acl.PermissionRole;

public interface PermRoleRepository extends JpaRepository<PermissionRole, Long> {
  PermissionRole findByName(String roleName);
  
  @Transactional(readOnly=true)
  @Query("select p from PermissionRole p left join fetch p.permissionEntries where id= ?1")
  PermissionRole findOneWithPermissionEntries(Long id);
  
  @Transactional(readOnly=true)
  @Query("select distinct p from PermissionRole p left join fetch p.permissionEntries")//jay:plus distinct to prevent cross join
  List<PermissionRole> findAllWithPermissionEntries();
}
